#include <string.h>
#include <iostream>
using std::cout;
using std::endl;

class Computer{
public:
    Computer(const char *brand,float price)
     :_brand(new char[strlen(brand)+1]()),
     _price(price)
    {
        strcpy(_brand,brand);
        total_price +=price;
        cout<<"total_price:"<<total_price<<endl;
    }

    Computer(const Computer &rhs) {
        if(rhs._brand){
        _price = rhs._price;
        _brand = new char[strlen(rhs._brand)+1]();
        strcpy(_brand,rhs._brand);
        total_price +=_price;
        cout<<"total_price:"<<total_price<<endl;
        }
    }

    Computer &operator=(const Computer &rhs){
        if(this !=&rhs){
            delete[]_brand;
            //TODO:要先减去原先的
            _price = rhs._price;
            _brand = new char[strlen(rhs._brand)+1]();
            total_price +=_price;
        cout<<"total_price:"<<total_price<<endl;
        }
        return *this;
    }

    ~Computer(){
        delete[] _brand;
    }
        

    static float total_price;
private:
    char  *_brand;
    float _price;
};

float Computer::total_price = 0;

void test(){
    Computer c1("zs",2000);
    Computer c2("ls",5500);

}

int main()
{
    

    test ();
    return 0;
}

